using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using WpfClient.Infrastructure.Data;
using WpfClient.Infrastructure.Services;
using WpfClient.Core.Interfaces;
using WpfClient.Infrastructure.Data.Repositories;
using WpfClient.Core.Services;
using WpfClient.Core.Communication;
using WpfClient.Infrastructure.Communication;

namespace WpfClient.Infrastructure
{
    /// <summary>
    /// 基础设施层依赖注入配置
    /// </summary>
    public static class DependencyInjection
    {
        public static IServiceCollection AddInfrastructureServices(this IServiceCollection services)
        {
            // 配置数据库上下文
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite("Data Source=wpfclient.db"));

            // 注册仓储
            services.AddScoped(typeof(IRepository<>), typeof(BaseRepository<>));
            
            // 注册核心服务
            services.AddScoped<IUserService, UserService>();
            
            // 注册基础设施服务
            services.AddScoped<LoggingService>();
            
            // 注册Socket通信服务
            services.AddSingleton<ISocketServer, SocketServer>();
            services.AddSingleton<ISocketCommunicationService, SocketCommunicationService>();
            
            return services;
        }
    }
}